package com.yytek.upgrade.controller;

import java.util.List;
import java.io.IOException;

import com.yytek.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.upgrade.domain.UpgradeStrategyDeviceTopo;
import com.yytek.upgrade.service.IUpgradeStrategyDeviceTopoService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 升级策略设备关联Controller
 * 
 * @author yytek-iot
 * @date 2022-09-06
 */
@Api(value = "升级策略设备关联控制器", tags = {"升级策略设备关联管理"})
@RestController
@RequestMapping("/topo")
public class UpgradeStrategyDeviceTopoController extends BaseController
{
    @Autowired
    private IUpgradeStrategyDeviceTopoService upgradeStrategyDeviceTopoService;

    /**
     * 根据策略id获取升级策略绑定设备列表
     * @param id 策略id
     * @return
     */
    @ApiOperation("查询升级策略设备关联列表")
    @GetMapping("/getBindDeviceTopo")
    public R<List<UpgradeStrategyDeviceTopo>> getBindDeviceTopo(Long id)
    {
        List<UpgradeStrategyDeviceTopo> list = upgradeStrategyDeviceTopoService.selectUpgradeStrategyDeviceTopoByStrategyId(id);
        return R.ok(list);
    }
    /**
     * 批量升级策略设备绑定
     */
    @ApiOperation("批量升级策略设备绑定")
    @Log(title = "批量升级策略设备绑定", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<UpgradeStrategyDeviceTopo> topoList)
    {
        return toAjax(upgradeStrategyDeviceTopoService.insertUpgradeStrategyDeviceTopoList(topoList));
    }

    /**
     * 查询升级策略设备关联列表
     */
    @ApiOperation("查询升级策略设备关联列表")
    @RequiresPermissions("upgrade:topo:list")
    @GetMapping("/list")
    public TableDataInfo list(UpgradeStrategyDeviceTopo upgradeStrategyDeviceTopo)
    {
        startPage();
        List<UpgradeStrategyDeviceTopo> list = upgradeStrategyDeviceTopoService.selectUpgradeStrategyDeviceTopoList(upgradeStrategyDeviceTopo);
        return getDataTable(list);
    }

    /**
     * 导出升级策略设备关联列表
     */
    @ApiOperation("导出升级策略设备关联列表")
    @RequiresPermissions("upgrade:topo:export")
    @Log(title = "升级策略设备关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpgradeStrategyDeviceTopo upgradeStrategyDeviceTopo)
    {
        List<UpgradeStrategyDeviceTopo> list = upgradeStrategyDeviceTopoService.selectUpgradeStrategyDeviceTopoList(upgradeStrategyDeviceTopo);
        ExcelUtil<UpgradeStrategyDeviceTopo> util = new ExcelUtil<UpgradeStrategyDeviceTopo>(UpgradeStrategyDeviceTopo.class);
        util.exportExcel(response, list, "升级策略设备关联数据");
    }


    /**
     * 新增升级策略设备关联
     */
    @ApiOperation("新增升级策略设备关联")
    @RequiresPermissions("upgrade:topo:add")
    @Log(title = "升级策略设备关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UpgradeStrategyDeviceTopo upgradeStrategyDeviceTopo)
    {
        return toAjax(upgradeStrategyDeviceTopoService.insertUpgradeStrategyDeviceTopo(upgradeStrategyDeviceTopo));
    }

    /**
     * 修改升级策略设备关联
     */
    @ApiOperation("修改升级策略设备关联")
    @RequiresPermissions("upgrade:topo:edit")
    @Log(title = "升级策略设备关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UpgradeStrategyDeviceTopo upgradeStrategyDeviceTopo)
    {
        return toAjax(upgradeStrategyDeviceTopoService.updateUpgradeStrategyDeviceTopo(upgradeStrategyDeviceTopo));
    }

    /**
     * 删除升级策略设备关联
     */
    @ApiOperation("删除升级策略设备关联")
    @RequiresPermissions("upgrade:topo:remove")
    @Log(title = "升级策略设备关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{strategyIds}")
    public AjaxResult remove(@PathVariable Long[] strategyIds)
    {
        return toAjax(upgradeStrategyDeviceTopoService.deleteUpgradeStrategyDeviceTopoByStrategyIds(strategyIds));
    }
}
